package thread;

import java.util.concurrent.locks.ReentrantLock;

/**
 * Creared with IntelliJ IDEA.
 * Description:另一种可重入锁
 * User:yxd
 * Date:2022-04-01
 * Time:23:59
 */
public class Demo29 {
    public static void main(String[] args) {
        ReentrantLock locker1 = new ReentrantLock(true);//公平锁

        ReentrantLock locker = new ReentrantLock();
        //加锁
        locker.lock();
        //如果这里有抛出异常的话,后面的unlock很有可能执行不到,然后导致死锁,因此这里一般的写法就是unlock放到finally里面保证一定能执行到
        //解锁
        locker.unlock();
        //这里将加锁和解锁区分开了
    }
}
